let Cesium: any = undefined;
let dfSt: any = undefined;
import {_installWaveCircleMaterial} from "./js/waveCircleMaterial";
import {_installCircleFadeMaterial} from "./js/CircleFadeMaterial";
import {_installCityLineMaterial} from "./js/CityLineMaterial";
import {_installWarnMaterial} from "./js/WarnMaterial";
import {_installFlowMaterial} from "./js/FlowMaterial";
import {_installPolylineTrailLinkMaterial} from "./js/PolylineTrailLinkMaterial";
import {_initPolylineCustomMaterialProperty} from "./js/PolylineCustomMaterialProperty";
import {_initWallCustomMaterialProperty} from "./js/WallCustomMaterialProperty";

/**
 * 材质模块
 * @class
 * @augments  module:Base
 * @param {object}  viewer - cesium 实例
 * @param {object}  cesiumGlobal - cesium 全局对象
 * @param {Array}  defaultStatic - 静态资源
 * @exports  Material
 */
class Material {
    private _viewer: any;
    constructor(viewer: any, cesiumGlobal: any, defaultStatic: any) {
        if (viewer) {
            Cesium = cesiumGlobal;
            dfSt = defaultStatic;
            this._viewer = viewer;
            this._installMaterial();
        }
    }

    /**
     * 安装默认拓展材质
     * @private
     */
    _installMaterial() {
        _installWaveCircleMaterial(Cesium);

        _installCircleFadeMaterial(Cesium);

        _installCityLineMaterial(dfSt,Cesium)
        _installWarnMaterial(dfSt,Cesium)
        _installFlowMaterial(Cesium);
        _installPolylineTrailLinkMaterial(dfSt,Cesium);
    }

    /**
     * 添加动态炫光线材质
     * @function
     * @param {object} options
     * @param {string} options.image - 图片url
     * @param {Cartesian3} options.positions - 坐标
     * @param {Color} options.color - 颜色
     * @param {number} options.duration - 持续时长
     * @param {number} options.width - 宽度
     * @example
     *  import { Material } from 'cesium_dev_kit'
     * const {material,viewer} = new Material({
     *     cesiumGlobal: Cesium,
     *     containerId: 'cesiumContainer'
     * })
     *  material.addMaterialLineGraphics({
     *     positions:Cesium.Cartesian3.fromDegrees(104.081701757991, 30.627042558105988, 400.0)
     *     color:Cesium.Color.GREEN,
     *     image:'static/data/images/Textures/billboard2.png',
     *     duration:500,
     *     width:2
     * })
     * @returns {polyline} 返回polyline实例
     */
    addMaterialLineGraphics(options: any) {
        if (this._viewer && options && options.image) {
            var _entity = this.createGraphics();

            _entity.polyline = {
                positions: options.positions,
                material: new Cesium.PolylineCustomMaterialProperty({
                    color: options.color || Cesium.Color.RED,
                    duration: options.duration || 500,
                }),
                width: options.width,
            };

            return this._viewer.entities.add(_entity);
        }
    }

    /**
     * 获取一个动态线材质
     * @param {object} options
     * @param {string} options.image - 图片url
     * @param {number} options.duration - 持续时长
     * @param {Color} options.color - 颜色
     * @param {JulianDate} options.time - Julian时间
     * @example
     * import { initCesium } from 'cesium_dev_kit'
     * const {viewer,graphics,material} = new initCesium({
     *     cesiumGlobal: Cesium,
     *     containerId: 'cesiumContainer'
     * })
     * const materialCust =   material.getCustomMaterialLine({
     *     color:Cesium.Color.GREEN,
     *     image:'static/data/images/Textures/billboard2.png',
     *     duration:1005,
     *     time:Cesium.JulianDate.fromIso8601("2024-05-19 15:36"),
     * })
     *  graphics.getLineGraphics({
     *     positions:Cesium.Cartesian3.fromDegreesArray([
          104.09816110606057,
          30.659821965447698,
          104.1120972824757,
          30.65330300319938,
          104.10758419863926,
          30.64592470850288,
          104.09351691196979,
          30.652434826507452,
          104.09816110606057,
          30.659821965447698
        ]),
     *      material:materialCust,
     *      clampToGround:false,
     *      width:1
     * })
     * @returns {PolylineCustomMaterialProperty}
     */
    getCustomMaterialLine(options: any) {
        if (this._viewer && options && options.image) {
            // 初始化自定义材质线
            return _initPolylineCustomMaterialProperty(options,Cesium);
        }
    }

    /**
     * 添加 动态围栏/炫光墙体
     * @function
     * @param {string} options.image - 图片url
     * @param {number} options.duration - 持续时长
     * @param {Color} options.color - 颜色
     * @param {number} options.width - 宽度
     * @see {@link module:Graphics#createFanShape|Graphics#createFanShape}
     * @example
     *  import { Material } from 'cesium_dev_kit'
     * const {material,viewer} = new Material({
     *     cesiumGlobal: Cesium,
     *     containerId: 'cesiumContainer'
     * })
     * // 创建炫光墙体
     material.addMaterialWallGraphics({
         positions: Cesium.Cartesian3.fromDegreesArrayHeights([
          104.07263175401185,
          30.647622150198725,
          500.0,
          104.06369117158526,
          30.648834374000277,
          500.0,
          104.06437182811021,
          30.62274533905387,
          500.0,
          104.07463538167119,
          30.62285687644371,
          500.0,
          104.07263175401185,
          30.647622150198725,
          500.0
        ]),
        width:1200,
        image:  'static/data/images/Textures/test1.png',,
        color:   Cesium.Color.BLUE,,
        duration: 2000
      });
     * @returns {wall} 返回wall实例
     */
    addMaterialWallGraphics(options: any) {
        if (this._viewer && options && options.image) {
            var _entity = this.createGraphics();
            _entity.wall = {
                positions: options.positions,
                material: this.getCustomMaterialWall(options),
                width: options.width,
            };

            return this._viewer.entities.add(_entity);
        }
    }


    /**
     * 获取一个材质围栏
     * @function
     * @param {object} options
     * @param {string} options.image - 图片url
     * @param {number} options.duration - 持续时长
     * @param {Color} options.color - 颜色
     * @param {number} options.count - 频率
     * @param {string} options.freely - 方向，可选["vertical"|"cross"]
     * @param {string} options.direction - 方向,可选["-"|"+"]
     * @see {@link module:Graphics#createFanShape|Graphics#createFanShape}
     * @example
     *  import { initCesium } from 'cesium_dev_kit'
     * const {material,graphics,viewer} = new initCesium({
     *     cesiumGlobal: Cesium,
     *     containerId: 'cesiumContainer'
     * })
     * // 创建动态材质
     const custMaterial = material.getCustomMaterialWall({
        image:  'static/data/images/Textures/test1.png',,
        freely:  'cross',
        direction: '+',
        count: 0.0,,
        color:   Cesium.Color.BLUE,,
        duration: 2000
      });

     // 创建扇形扫描
     graphics.createFanShape({
        viewer,
        longitude: 104.06417395476578,
        latitude: 30.636185094244944,
        alt: 700,
        speed: 2.0,
        direction: '+',
        custMaterial
      })
     * @returns {WallLinkCustomMaterialProperty}
     */
    getCustomMaterialWall(options: any) {
        if (this._viewer && options && options.image) {
            return _initWallCustomMaterialProperty(options,Cesium);
        }
    }

    createGraphics() {
        return new Cesium.Entity();
    }
}


export default Material;
